<template>
  <div>
    <!-- 新增，返回按钮 -->
    <div style="display: flex; justify-content: space-between">
      <div>
        <el-button type="primary" @click="dialog = true">添加权益卡</el-button>
      </div>
      <el-button @click="$emit('send')">返回</el-button>
    </div>
    <!-- 搜索，筛选 -->
    <div style="margin-top: 10px">
      <el-input
        v-model="filterInp"
        placeholder="请输入权益卡名称"
        style="width: 17%; margin-right: 10px"
      />
      <el-button
        :loading="filterLoad"
        type="primary"
        @click="getEquitycard('filterLoad')"
      >
        筛选
      </el-button>
    </div>
    <!-- 权益卡展示列表 -->
    <div style="margin-top: 10px">
      <!-- 权益卡展示表格 -->
      <el-table :data="tableData" :empty-text="emptyText">
        <el-table-column label="权益卡名称" prop="coupon_name" />
        <el-table-column label="权益卡类型" prop="coupon_type_name" />
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary" @click="openDialog('编辑', scope.row)">
              编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div style="display: flex; justify-content: space-between">
        <div></div>
        <el-pagination
          :current-page.sync="page"
          layout="prev, pager, next, jumper"
          :total="total"
          @current-change="getEquitycard"
        />
      </div>
    </div>

    <el-dialog title="权益卡" :visible.sync="dialog">
      <AddEquityCard :o-equity-card-info="equityCardInfo" @send="over" />
    </el-dialog>
  </div>
</template>

<script>
  export default {
    components: {
      AddEquityCard: () => import('./components/addequitycard.vue'),
    },
    data() {
      return {
        filterInp: '',
        filterLoad: false, // 筛选按钮加载样式

        emptyText: ' ',
        tableData: [], // 权益卡列表数据
        page: 1, // 分页条数，初始化为1
        total: 10,

        dialog: false,
        equityCardInfo: {}, // 存放选中权益卡的详情信息
      }
    },
    mounted() {
      this.getEquitycard()
    },
    methods: {
      // 获取权益卡列表
      getEquitycard() {
        const loading = this.$loading({
          loack: true,
          target:
            this.tableData.length == 0
              ? '.el-table__empty-block'
              : '.el-table__body',
        })

        setTimeout(() => {
          loading.close()
        }, 2000)
      },
      over() {
        this.dialog = false
        this.getEquitycard()
      },
    },
  }
</script>

<style scoped></style>
